#include "../include/scriptslist.h"

ScriptsList::ScriptsList() {
	this->updateScripts();
}

void ScriptsList::updateScripts(string scriptsDirName) {
	this->scripts.clear();

	string homedir = getHomeDir();

	string path = homedir + "/" + scriptsDirName;
	for (const auto &entry : filesystem::directory_iterator(path)) {
		string epath = entry.path();
		string exec = "sh " + epath;

		string name = epath.substr(path.length()+1, epath.length());
		name = name.substr(0, name.length()-3);

		this->scripts[name] = exec;
	}
}

void ScriptsList::printScriptNames() {
	for (const auto &scriptItem : this->scripts) {
		cout << scriptItem.first << endl;
	}
}
